package com.example.springboottest;

import com.example.springboottest.interceptor.UpdateInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@MapperScan("com.example.springboottest.**.mapper")
@EnableCaching
@EnableTransactionManagement
//开始spring security
//@EnableWebSecurity
//开始定时任务
//@EnableScheduling
@EnableHystrix
public class SpringBootTestApplication implements WebMvcConfigurer {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootTestApplication.class, args);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**注册拦截器到 SpringMVC 机制， 然后它会返回一个拦截器注测
         * 如果有多个拦截器，按顺序执行
         **/
        InterceptorRegistration ir = registry.addInterceptor(new UpdateInterceptor());
        //指定拦截匹配模式，限制拦截器拦截请求
        ir.addPathPatterns("/*/update*");
    }
}